#include <stdio.h>
#include <string.h>
#include <stdlib.h>

typedef struct stu
{
    char name[128];
    char sex[64];
    int age;
} stu;

stu data[50] =
    {
        {.name = "张三", .sex = "男", .age = 18},
        {.name = "李四", .sex = "男", .age = 20},
        {.name = "王五", .sex = "男", .age = 19},
};

int main()
{
    FILE *fp = fopen("1.txt", "r+");
    if (fp == NULL)
    {
        printf("文件打开失败");
        return -1;
    }

    for (size_t i = 0; i < 3; i++)
    {
        fprintf(fp, "姓名:%s\t性别:%s\t年龄:%d\n", data[i].name, data[i].sex, data[i].age);
    }

    fclose(fp);
    fp = NULL;

    fp = fopen("1.txt", "r+");
    if (fp == NULL)
    {
        printf("文件打开失败");
        return -1;
    }

    for (size_t i = 0; i < 3; i++)
    {
        fscanf(fp, "姓名:%s\t性别:%s\t年龄:%d\n",data[i].name,data[i].sex,&data[i].age);
    }

        for (size_t i = 0; i < 3; i++)
    {
        fprintf(stdout, "姓名:%s\t性别:%s\t年龄:%d\n", data[i].name, data[i].sex, data[i].age);
    }

    fclose(fp);
    fp = NULL;
    return 0;
}